
//
//  BStripleECGViewController.m
//  SuoSiApp
//
//  Created by 张明阳 on 16/4/21.
//  Copyright © 2016年 Ym. All rights reserved.
//

#import "ZipArchive.h"
#import "StringResponse.h"
#import "AsyncSocket.h"
#import "BSMainInterfaceViewControllerViewController.h"

#import "TripleECGView.h"
#import "BStripleECGViewController.h"
#import "BSSingleChannelViewController.h"


@interface BStripleECGViewController ()<UIGestureRecognizerDelegate,AsyncSocketDelegate>
{
    AsyncSocket *_socket;
    
}

//定时器是否暂停
@property (nonatomic, assign) BOOL isSuspend;

//测试的临时数组
@property (nonatomic, strong) NSMutableArray *testArr;
@property (nonatomic, strong) NSMutableArray *tempArr, *tempArr2,*tempArr3;
@property (nonatomic, strong) NSMutableArray *lastArr;

@property (nonatomic, assign) NSInteger index;
//第几个点
@property (nonatomic, assign) NSInteger pointIndex;

@property (nonatomic, assign) BOOL isSocketConnected;

//每次处理的数据的时间
@property (nonatomic, assign) NSInteger drawingCountOnce;

// 差值多少 代表1毫伏
@property (nonatomic, assign) NSInteger pointKK;


@end


@implementation BStripleECGViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _isSuspend = NO;
    _pointIndex = 0;
    _drawingCountOnce = 5;
    _pointKK = 330;
#pragma mark test 批量上传
//    [self updateBatch];
    
    __weak BStripleECGViewController *mySelf = self;
    [BSBluetoothSingleton shareBlutooth].getsignal = ^void(){

        [mySelf setRSSIImage];
        
    };
    
    [self popDataTimerEvent];

    [self.ecgView removeFromSuperview];

//    计算下 满屏的宽度
    CGFloat height1 = self.currentSpeedLB.bottom + kMartin10;
//    三通道
    CGFloat kmm = 0;
    if (kScrenWidth > 380) {
        kmm = k6pmm;
    } else {
        kmm = k1mm;
    }
    CGFloat height2 = kmm * 12 ;
    
    CGFloat height3 = kMartin10 + self.modeView.bottom - self.adjustSpeedLB.top;
    
    CGFloat height = height1 + height2 + height3;

    [self addScrollViewWithheight:height];
    
    [super addSubview];
    [self addViews];
    [self removeSubviews];
    
//    跳转方法
    [self.threeeChannelBT addTarget:self action:@selector(singleECGView) forControlEvents:(UIControlEventTouchUpInside)];
    

#pragma mark 添加手势
    [self addTap];
    
#pragma mark 创建socket通信
    UILongPressGestureRecognizer *longGes = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(uploadNow:)];
    longGes.minimumPressDuration = 1;
    [self.batchBT addGestureRecognizer:longGes];
    
    [self creatSocketConnection];
    self.speed10BT.selected = YES;

    [self observeHeartRate];

//    [self updateBatch];
    
    
#pragma mark  测试用方法 找到1mm 对应的合适的点
    [self testPoint];
    
}
- (void)testPoint{
    UIButton *button1 = BSButton;
    button1.frame = CGRectMake(kScrenWidth/3 * 2, 40, 40, 20);
    [button1 addTarget:self action:@selector(button1) forControlEvents:(UIControlEventTouchUpInside)];
    button1.backgroundColor = BSWhite;
    [button1 setTitle:@"+ 3" forState:(UIControlStateNormal)];
    [button1 setTitleColor:BSRed forState:(UIControlStateNormal)];
    [self.view addSubview:button1];
    
    UIButton *button2 = BSButton;
    button2.frame = CGRectMake(kScrenWidth/3 * 2 + 50, 40, 40, 20);
    [button2 addTarget:self action:@selector(button2) forControlEvents:(UIControlEventTouchUpInside)];
    button2.backgroundColor = BSWhite;
    [button2 setBackgroundImage:[UIImage imageNamed:@"180icon.png"] forState:(UIControlStateNormal)];

    [button2 setTitle:@"- 3" forState:(UIControlStateNormal)];
    [button2 setTitleColor:BSRed forState:(UIControlStateNormal)];
    [self.view addSubview:button2];
    
    UIButton *button3 = BSButton;
    button3.frame = CGRectMake(kScrenWidth/3 * 2 + 50, 70, 40, 20);
    [button3 addTarget:self action:@selector(button3) forControlEvents:(UIControlEventTouchUpInside)];
    button3.backgroundColor = BSWhite;

    [button3 setTitle:@"OK" forState:(UIControlStateNormal)];
    [button3 setTitleColor:BSRed forState:(UIControlStateNormal)];
    [self.view addSubview:button3];

}
- (void)button1{
    
    for (int i = 0; i < 3; i++) {
        TripleECGView *view = self.ecgViewsArr[i];
//        view.pointMartin = 0.6;
        
        _pointKK += 3;
         view.heartAmplitude = _pointKK;
        view.bbb += 1;
    }
    

}
- (void)button2{
    for (int i = 0; i < 3; i++) {
        TripleECGView *view = self.ecgViewsArr[i];
        //        view.pointMartin = 0.6;
        _pointKK -= 3;
         view.heartAmplitude = _pointKK;
    }
}

- (void)button3{
    
    NSString *str = @"";
    for (int i = 0; i < 3; i++) {
        TripleECGView *view = self.ecgViewsArr[i];
        //        view.pointMartin = 0.6;
        
        str = [NSString stringWithFormat:@"%ld",(long)_pointKK];
    }
    [PKRequestManager showAlertView:str];
}


- (void)creatSocketConnection{
    // 1.创建socket
    _socket = [[AsyncSocket alloc] initWithDelegate:self];
    // 2.与服务器建立连接 192.168.1.109
    

    [_socket connectToHost:@"192.168.1.134" onPort:9999 error:nil];

}
//立马上传数据
- (void)uploadNow:(UILongPressGestureRecognizer *)longGes{
    if (_isSocketConnected == NO) {
        [self creatSocketConnection];
    }
    if (longGes.state == UIGestureRecognizerStateBegan) {
        NSLog(@"实时上传");
 
        [self.batchBT setTitle:@"实时模式" forState:(UIControlStateNormal)];
        [self.batchBT setTitleColor:BSYellow forState:(UIControlStateNormal)];
        
        
        NSData *data = [self uploadDataNow];
        [_socket writeData:data withTimeout:1 tag:1];
    }
    if (longGes.state == UIGestureRecognizerStateEnded) {
        NSLog(@"批量上传");
        [self.batchBT setTitle:@"批量模式" forState:(UIControlStateNormal)];
        [self.batchBT setTitleColor:BSWhite forState:(UIControlStateNormal)];
    }
}


#pragma mark - AsyncSocketDelegate
// 与服务器成功建立连接
-(void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port {
    NSLog(@"与服务器建立连接");
    // 开始读取服务器发送过来的数据
    [_socket readDataWithTimeout:2 tag:1];
    _isSocketConnected = YES;
}
// 读取数据
- (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag {
    // data:可能是图片、JSON数据、字符串、XML
    // 使用服务器发送过来的数据
    NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    //    NSLog(@"服务器:%@",str);
     // 开始读取服务器发送过来的数据
    [_socket readDataWithTimeout:-1 tag:0];
    
}
// 写入数据
- (void)onSocket:(AsyncSocket *)sock didWriteDataWithTag:(long)tag {
    NSLog(@"写入成功");
}
// 连接失败
- (void)onSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)err {
    NSLog(@"连接失败");
    _isSocketConnected = NO;

}
// 断开连接
- (void)onSocketDidDisconnect:(AsyncSocket *)sock {
    NSLog(@"断开连接");
    _isSocketConnected = NO;

}


//手势
- (void)addTap{
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:nil];
    tap.delegate = self;
    [self.view addGestureRecognizer:tap];
    

}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    
  NSString *str =  NSStringFromClass([touch.view class]);
//    NSLog(@"%@",NSStringFromClass([touch.view class]));
    if ([str isEqualToString:@"TripleECGView"]) {
//控制定时器是否暂停
        if (_isSuspend == NO) {
//            关闭定时器
            [self.popDataTimer setFireDate:[NSDate distantFuture]];
            _isSuspend = YES;
            
        } else {
//            开启定时器
            [self.popDataTimer setFireDate:[NSDate distantPast]];
            _isSuspend = NO;
        }
    }
    return YES;
}



- (void)addViews
{
    NSMutableArray *array = [[NSMutableArray alloc] init];
    
    //    leadCount 设置显示区域的数目  有三个
    for (int i=0; i<3; i++) {
        
        TripleECGView *ecgView = [[TripleECGView alloc] init];
        ecgView.layer.cornerRadius = 8;
        ecgView.layer.borderColor = [[UIColor grayColor] CGColor];
        ecgView.layer.borderWidth = 1;
        ecgView.clipsToBounds = YES;
        ecgView.index = i;
        ecgView.pointArray = [[NSMutableArray alloc]init];
        [self.scrollView addSubview:ecgView];
        [array addObject:ecgView];
    }
    //	把创建的三个显示区域 都放在数组里面 看看后面怎么用
    self.ecgViewsArr = array;
    
    [self setECGViews];
    
}

- (void)setECGViews{
    

    CGFloat kmm = 0;
    if (kScrenWidth > 380) {
        kmm = k6pmm;
    } else {
        kmm = k1mm;
    }
    
    for (int i = 0; i < 3; i++) {
        TripleECGView *ecgView = (TripleECGView *)[self.ecgViewsArr objectAtIndex:i];
        [ecgView setFrame:CGRectMake(5, self.currentSpeedLB.bottom + kMartin10 * (i + 1)  + i *(kmm * 4) , kScrenWidth - 10, kmm * 4)];
        ecgView.alpha = 1;
        
        if (i == 0) {
            ecgView.channelLB.text = @"MII";
        }
        if (i == 1) {
            ecgView.channelLB.text = @"MV1";
        }
        if (i == 2) {
             ecgView.channelLB.text = @"MV5";
        }
        
    
        [self.scrollView addSubview:ecgView];
    }
    
       //    这个动画不知道他的意义 是什么 在前面就可以设定leadPlayer的alpha
    [UIView animateWithDuration:0.6f animations:^{
        for (int i=0; i<3; i++)
        {
            TripleECGView *ecgView = [self.ecgViewsArr objectAtIndex:i];

            ecgView.alpha = 1;
        }
    }];
}

//
- (void)removeSubviews{
    [self.lineView removeFromSuperview];
    [self.currentChannelLB  removeFromSuperview];
    [self.MIIBT removeFromSuperview];
    [self.MV1BT removeFromSuperview];
    [self.MV5BT removeFromSuperview];

    self.speed5BT.top = self.MIIBT.top;
    
    [self.speed5BT addTarget:self action:@selector(speed5mm:) forControlEvents:(UIControlEventTouchUpInside)];
    
    self.speed10BT.top = self.speed5BT.top;
    
    [self.speed10BT addTarget:self action:@selector(speed10mm:) forControlEvents:(UIControlEventTouchUpInside)];
    
     self.speed20BT.top = self.speed5BT.top;
    
    [self.speed20BT addTarget:self action:@selector(speed20mm:) forControlEvents:(UIControlEventTouchUpInside)];
    self.adjustSpeedLB.top = self.currentChannelLB.top;
    self.lineView2.top = self.lineView.top;

}
// 调节走纸速度
- (void)speed5mm:(UIButton *)sender{

    self.currentSpeedLB.text = @"当前速度: 5mm/mV 12.5mm/s ";
    
    for (int i = 0; i < 3; i++) {
        TripleECGView *view = self.ecgViewsArr[i];
        view.pointMartin = 0.6;
//        view.heartAmplitude = _pointKK * 2;
        view.kkk = 2;
    }
    

    if (sender.selected == NO) {
        sender.selected = !sender.selected;

    }
    
    self.speed10BT.selected = NO;
    self.speed20BT.selected = NO;
    
}
- (void)speed10mm:(UIButton *)sender{
     self.currentSpeedLB.text = @"当前速度: 10mm/mV 25mm/s ";
    
    for (int i = 0; i < 3; i++) {
        TripleECGView *view = self.ecgViewsArr[i];
        view.pointMartin = 1.2;
        view.heartAmplitude = _pointKK;
         view.kkk = 1;
    }

    if (sender.selected == NO) {
        sender.selected = !sender.selected;
        
    }    NSLog(@"%d",sender.selected);
    self.speed5BT.selected = NO;
    self.speed20BT.selected = NO;

}

- (void)speed20mm:(UIButton *)sender{

     self.currentSpeedLB.text = @"当前速度: 20mm/mV 50mm/s ";

    for (int i = 0; i < 3; i++) {
        TripleECGView *view = self.ecgViewsArr[i];
        view.pointMartin = 2.4;
//        view.heartAmplitude = _pointKK/2;
         view.kkk = 0.5;
    }


    if (sender.selected == NO) {
        sender.selected = !sender.selected;
        
    }    self.speed10BT.selected = NO;
    self.speed5BT.selected = NO;

}


- (void)singleECGView{
    

    BSSingleChannelViewController *singleVC = [[BSSingleChannelViewController alloc]init];
    
    singleVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    
    [self.navigationController pushViewController:singleVC animated:YES];


}

- (void)viewWillAppear:(BOOL)animated{
    //开启定时器
    [self.popDataTimer setFireDate:[NSDate distantPast]];
    _tempArr = [[NSMutableArray alloc]init];
    _lastArr =  [[NSMutableArray alloc]init];
}
- (void)viewWillDisappear:(BOOL)animated{

//关闭定时器
    [self.popDataTimer setFireDate:[NSDate distantFuture]];

}

- (void)popDataTimerEvent{

    self.popDataTimer = [NSTimer scheduledTimerWithTimeInterval:0.04 target:self selector:@selector(popData) userInfo:nil repeats:YES];
    _index = 0;
}

- (void)popData{
    

    [_tempArr removeAllObjects];
    [_tempArr2 removeAllObjects];

    TripleECGView *view = self.ecgViewsArr[0];
    TripleECGView *view2 = self.ecgViewsArr[1];
    TripleECGView *view3 = self.ecgViewsArr[2];

    [view.pointArray removeAllObjects];
    [view2.pointArray removeAllObjects];
    [view3.pointArray removeAllObjects];

    
    if ([BSBluetoothSingleton shareBlutooth].chanel1Arr != nil && [BSBluetoothSingleton shareBlutooth].chanel1Arr.count >= _drawingCountOnce) {
//    判断数组里面还剩多少点 够不都画得了
 
            NSArray *arr = [[BSBluetoothSingleton shareBlutooth].chanel1Arr subarrayWithRange:NSMakeRange(0, _drawingCountOnce)];
            
            _tempArr = [NSMutableArray arrayWithArray:arr];
            
            [[BSBluetoothSingleton shareBlutooth].chanel1Arr removeObjectsInRange:NSMakeRange(0, _drawingCountOnce)];
       // NSLog(@"%ld",(unsigned long)[BSBluetoothSingleton shareBlutooth].ECGDataArrWithArr.count);
     
    }
    if ([BSBluetoothSingleton shareBlutooth].chanel2Arr != nil && [BSBluetoothSingleton shareBlutooth].chanel2Arr.count >= _drawingCountOnce) {
        //    判断数组里面还剩多少点 够不都画得了
        
        NSArray *arr = [[BSBluetoothSingleton shareBlutooth].chanel2Arr subarrayWithRange:NSMakeRange(0, _drawingCountOnce)];
        
        _tempArr2 = [NSMutableArray arrayWithArray:arr];
        
        [[BSBluetoothSingleton shareBlutooth].chanel2Arr removeObjectsInRange:NSMakeRange(0, _drawingCountOnce)];
        // NSLog(@"%ld",(unsigned long)[BSBluetoothSingleton shareBlutooth].ECGDataArrWithArr.count);
        
    }
    if ([BSBluetoothSingleton shareBlutooth].chanel3Arr != nil && [BSBluetoothSingleton shareBlutooth].chanel3Arr.count >= _drawingCountOnce) {
        //    判断数组里面还剩多少点 够不都画得了
        
        NSArray *arr = [[BSBluetoothSingleton shareBlutooth].chanel3Arr subarrayWithRange:NSMakeRange(0, _drawingCountOnce)];
        
        _tempArr3 = [NSMutableArray arrayWithArray:arr];
        
        [[BSBluetoothSingleton shareBlutooth].chanel3Arr removeObjectsInRange:NSMakeRange(0, _drawingCountOnce)];
        // NSLog(@"%ld",(unsigned long)[BSBluetoothSingleton shareBlutooth].ECGDataArrWithArr.count);
        
    }

    if (_tempArr.count > 0) {
        view3.pointArray = _tempArr3;
        view2.pointArray = _tempArr2;
        view.pointArray = _tempArr;
          [view fireDrawing];

        [view3 fireDrawing];
        [view2 fireDrawing];

//      NSThread *thread =   [NSThread currentThread];
//        NSThread *thread = [NSThread alloc]initWithTarget:<#(nonnull id)#> selector:<#(nonnull SEL)#> object:<#(nullable id)#>;
//        NSLog(@">> 当前的线程 %@",thread);
//        NSLog(@"剩余的点数 >> %ld",[BSBluetoothSingleton shareBlutooth].ECGDataArrWithArr.count );

    }else{
    
        [view3 keepDrawing];
        [view2 keepDrawing];
        [view keepDrawing];

    }
    
    //    }



}

- (void)dealloc{
    [self.popDataTimer invalidate];
    self.popDataTimer = nil;
    
}
- (void)back{
//    BSMainInterfaceViewControllerViewController *mainVC;
    
    
    for (int i = 0; i < self.navigationController.viewControllers.count; i++) {
    
        UIViewController *vc =  self.navigationController.viewControllers[i];
        if ( [vc isMemberOfClass:[BSMainInterfaceViewControllerViewController class]]) {
            [self.navigationController popToViewController:vc animated:YES];
            return;
        }
    }
}

- (NSMutableArray *)tempArr{

    if (!_tempArr) {
        _tempArr = [[NSMutableArray alloc]init];
    }
    return _tempArr;
}

#pragma mark 添加触摸方法  点击三个屏幕是 暂停计数器
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    // UITouch保存手指的信息（触摸的点）
    UITouch *touch = [touches anyObject];
    
    // 取出当前触摸的点
    // 返回一个当前触摸的点，相对于传进去的参数view
    if (    [touch.view isKindOfClass:[TripleECGView class]]
) {
        NSLog(@"没想到吧");
    }

}

#pragma mark 实时上传的方法
- (NSData *)uploadDataNow{

    NSMutableData *data = [[NSMutableData alloc]init];

    NSData *filedata = [BSBluetoothSingleton shareBlutooth].NSMutableDataNOW;
    
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    //    设置时间格式
    formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss.SSS";
    //      设置实时上传的文件格式
    NSString *user_id = [BSUserSGton userHandle].user_id;
    //        NSMutableString *string = [[NSMutableString alloc]init];
    
    NSInteger user_id_length = [user_id length];
    
//            上传方式
//    str = [str stringByAppendingString:@"("];
    [data appendData:[@"(" dataUsingEncoding:NSASCIIStringEncoding]];
//    上传方式
   int  n = 3;
    NSData *dataNum = [NSData dataWithBytes:&n length:1];
    [data appendData: dataNum];
    
    
//    str = [str stringByAppendingString:@"NOW"];
    [data appendData:[@"NOW" dataUsingEncoding:NSASCIIStringEncoding]];
    
    //        user_id的长度
    NSData *dataUser_id_length = [NSData dataWithBytes:&user_id_length length:1];
    [data appendData: dataUser_id_length];
    //        user_id
    [data appendData:[user_id dataUsingEncoding:NSASCIIStringEncoding]];
    //        时间长度 格式
    NSString *dateStr = [formatter stringFromDate:[NSDate date]];
    NSInteger dateStrLength = [dateStr length] ;
    NSData *datadateStr = [NSData dataWithBytes:&dateStrLength length:1];
    [data appendData: datadateStr];
    [data appendData:[dateStr dataUsingEncoding:NSASCIIStringEncoding]];
    
//     文件的长度 int 小端
    
    int fileDataLength = (int)[filedata length];
    NSData *dataChangeBefore = [NSData dataWithBytes:&fileDataLength length:4];

//    int abs = htons(fileDataLength);
//    NSData *Datahtons = [NSData dataWithBytes:&abs length:4];
    [data appendData:dataChangeBefore];
//    添加文件
    [data appendData:filedata];
    [data appendData:[@")" dataUsingEncoding:NSASCIIStringEncoding]];
    return data;
}
#pragma mark 批量上传的方法
- (void)updateBatch{
    
    
    //    管理文件
    NSFileManager *filemanager = [NSFileManager defaultManager];
    
    NSArray *documents = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    
    NSString *path = @"/ECGData";
    
    NSString *filePath = [documents[0] stringByAppendingString:path];
    
    NSString *zipFile = [filePath stringByAppendingPathComponent:@"/20160510103203.zip"];
    BOOL isExist = [filemanager removeItemAtPath:zipFile error:nil];
    NSLog(@"%d",isExist);
    
    
    NSArray *listArrfile = [BSUserSGton getECGDataFileListFromPath:filePath];
    NSMutableArray *listArr = [NSMutableArray arrayWithArray:listArrfile];
    
    NSInteger countOffiles = listArrfile.count;
    
    
    NSString *user_id = [BSUserSGton userHandle].user_id;
    NSArray *arr = [[NSArray alloc]init];
    ZipArchive *za = [[ZipArchive alloc] init];
    [za CreateZipFile2:zipFile];
    //    [za addFileToZip:sourcePath5 newname:@"20160510103209.dat"];
    
    if (listArr == 0) {
        return;
    }
    
    if (listArr.count > 1) {
        arr = [listArr subarrayWithRange:NSMakeRange(0, 1)];
    }else{
        arr = listArr;
    }
    for (int i = 0; i < arr.count; i++) {
        
        NSString *ECGfile = [filePath stringByAppendingPathComponent:arr[i]];
        //        判断这个文件是否为空 为空 直接删除
        long  long int bytes = [[filemanager attributesOfItemAtPath:ECGfile error:nil] fileSize];
        NSLog(@"%lld",bytes);
        
        
        [za addFileToZip:ECGfile newname:arr[i]];
    }
    BOOL success = [za CloseZipFile2];
    NSLog(@"Zipped file with result %d",success);
    
    //    如果压缩成功 打包data  上传
    NSData *filedata = [NSData data];
    if (success) {
        
        NSURL *url2 = [NSURL fileURLWithPath:zipFile];
        
        filedata = [NSData dataWithContentsOfURL:url2];
        [filemanager removeItemAtPath:zipFile error:nil];
        
    }
    
    NSString *uuidStr = [BSBluetoothSingleton shareBlutooth].uuiduuid;
    
    [PKRequestManager ChangePwdWithnetUrl:NetStr upLoadWay:(NSString *)@"1" userID:user_id deviceID:(NSString *)uuidStr filenames:arr data:filedata method:POST finish:^(NSData *data) {
        //            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
        //            NSLog(@"%@",dic);
        //            上传成功 删除 从listArr arr  本地删除arr的文件  修改显示
        StringResponse *model = [[StringResponse alloc]init];
        [model dealNoNoteWithData:data];
        if ([model.Code isEqualToString:@"0"]) {
            for (int i = 0; i < arr.count; i++) {
                
                NSString *ECGfile = [filePath stringByAppendingPathComponent:arr[i]];
                //        判断这个文件是否为空 为空 直接删除
                [filemanager removeItemAtPath:ECGfile error:nil];
                
                NSLog(@"上传成功");
                [listArr removeObject:arr[i]];
//                _lableUploadNote.text = [NSString stringWithFormat:@"正在上传%u/%d个",_numberOffiles - (int)listArr.count,_numberOffiles];
                
                if (listArr.count == 0) {
//                    [_uploadButton setTitle:@"已完成" forState:(UIControlStateNormal)];
                    return;
                }
            }
            if (arr.count != 0) {
                [self updateBatch];
            }
            
        } else {
            [PKRequestManager showAlertView:model.Message];
//            _isUploading = NO;
        }
    } error:^(NSError *error) {
        ;
    }];

}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
